package gui;

import java.awt.AlphaComposite;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.plaf.basic.BasicScrollBarUI;

public class CustomizedScrollUI extends BasicScrollBarUI {

	private Image image;

	public CustomizedScrollUI() {
		try {
			image = ImageIO.read(new File("src\\gui\\Images\\ScrollBarUI.png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	protected JButton createEmptyButton() {
		JButton button = new JButton();
		Dimension zeroDimension = new Dimension(0, 0);
		button.setPreferredSize(zeroDimension);
		button.setMinimumSize(zeroDimension);
		button.setMaximumSize(zeroDimension);
		return button;
	}

	protected JButton createDecreaseButton(int orientation) {
		return createEmptyButton();
	}

	protected JButton createIncreaseButton(int orientation) {
		return createEmptyButton();
	}

	@Override
	protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
	}

	@Override
	protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
		g.translate(thumbBounds.x, thumbBounds.y);
		AffineTransform transform = AffineTransform.getScaleInstance(
				(double) thumbBounds.width / image.getWidth(null),
				(double) thumbBounds.height / image.getHeight(null));
		((Graphics2D) g).setComposite(AlphaComposite.getInstance(
				AlphaComposite.SRC_OVER, (float) (0.4)));
		((Graphics2D) g).drawImage(image, transform, null);
		g.translate(-thumbBounds.x, -thumbBounds.y);
	}
}
